package com.oneplatform.system.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jeesuite.common.CurrentRuntimeContext;
import com.jeesuite.common.annotation.ApiMetadata;
import com.jeesuite.common.constants.PermissionLevel;
import com.oneplatform.system.service.SequenceGenService;

/**
 * 
 * <br>
 * Class Name   : SequenceController
 *
 * @author jiangwei
 * @version 1.0.0
 * @date 2019年9月27日
 */
@RestController
@RequestMapping("/")
public class SequenceController {

    private @Autowired SequenceGenService sequenceGenService;

	
	@ApiMetadata(permissionLevel = PermissionLevel.Anonymous)
	@PostMapping("generate")
	public String getSequence(@RequestParam(value = "appId",required = false) String appId,@RequestParam("code") String code) {
		if(StringUtils.isBlank(appId))appId = CurrentRuntimeContext.getInvokeAppId();
        return sequenceGenService.genSequence(appId,code);
	}


	@ApiMetadata(permissionLevel = PermissionLevel.Anonymous)
	@PostMapping("batch_generate")
	public List<String> getSequences(
            @RequestParam(value = "appId",required = false) String appId,
            @RequestParam(value = "code") String code,
            @RequestParam(value = "count")Integer count
          ) {
		if(StringUtils.isBlank(appId))appId = CurrentRuntimeContext.getInvokeAppId();
		List<String> result = new java.util.ArrayList<String>(count);
		for (int i = 0; i < count; i++) {
			result.add(sequenceGenService.genSequence(appId,code));
		}
        return result;
	}

}
